﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class morning_delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request["ids"];
        if (string.IsNullOrEmpty(id))
        {
            this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('必须有相对应的个股才能编辑.');CloesPage();</script>");
        }
        else
        {
            string[] ids = id.Split(new char[] { ',' });

            List<int> tids = new List<int>();
            foreach (string arg in ids) 
            {
                int tag = 0;
                if (int.TryParse(arg, out tag)) 
                {
                    tids.Add(tag);
                }
            }

            WebsiteDataModel.WebsiteDataEntities de = new WebsiteDataModel.WebsiteDataEntities();
            var re = from a in de.XG_Detail
                     where tids.Contains(a.id)
                     select a;
            foreach (WebsiteDataModel.XG_Detail node in re)
            {
                de.XG_Detail.DeleteObject(node);
            }
            int num = de.SaveChanges();
            if (num > 0)
            {
                this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('删除成功.');CloesPage();</script>");
            }
            else 
            {
                this.ClientScript.RegisterStartupScript(GetType(), "initerror", "<script>alert('删除失败.');CloesPage();</script>");
            }
        }
    }

    //private bool HasId(string id) 
    //{
    //    return ids.IndexOf(string.Format(",{0},", id)) > 0 ? true : false;
    //}
}